Skip to content

fix: make replace no-op for empty search#22275

Open
nvphungdev wants to merge 1 commit into
apache:mainfrom
nvphungdev:codex/replace-empty-search-noop
Open

fix: make replace no-op for empty search#22275
nvphungdev wants to merge 1 commit into
apache:mainfrom
nvphungdev:codex/replace-empty-search-noop

Conversation

@nvphungdev
Copy link
Copy Markdown

Which issue does this PR close?

Rationale for this change

PostgreSQL treats replace(str, '', replacement) as a no-op. DataFusion currently inserts the replacement before every character and at both ends, so replace('abc', '', 'x') returns xaxbxcx instead of abc.

What changes are included in this PR?

  • Updates the string replace implementation so an empty search substring returns the original input string unchanged.
  • Adds regression coverage for Utf8, LargeUtf8, Utf8View, and SQL execution.

Are these changes tested?

Yes:

  • cargo fmt --all
  • cargo test -p datafusion-functions string::replace::tests::test_functions
  • cargo test -p datafusion-sqllogictest --test sqllogictests -- expr.slt:637
  • cargo clippy --all-targets --all-features -- -D warnings
  • git diff --check

Are there any user-facing changes?

Yes. replace now matches PostgreSQL-compatible behavior for an empty search substring.

@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels May 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PostgreSQL compatibility: replace with an empty search string should be a no-op

1 participant